package chapter4;

import com.rabbitmq.client.AMQP;
import com.rabbitmq.client.Channel;
import com.rabbitmq.client.Connection;
import com.rabbitmq.client.ConnectionFactory;

/**
 * Created by uu on 2017/6/19.
 */
public class alert_producer {
        private static final String AMQP_EXCHANGES="alerts";
        private static boolean autoAck = true; // 是否默认Ack
    public static void main(String[] args) throws Exception{
        ConnectionFactory factory =  new ConnectionFactory();
                /*factory.setUri("amqp://userName:password@hostName:portNumber/virtualHost");*/
        factory.setUsername("alert_user");
        factory.setPassword("alertme");
        factory.setVirtualHost("/");
        factory.setHost("localhost");
        factory.setPort(5672);
        Connection conn = factory.newConnection();
        Channel channel = conn.createChannel();
        AMQP.BasicProperties properties = new AMQP.BasicProperties.Builder().priority(1).contentType("text/plain").deliveryMode(2).build();
        byte[] messageBodyBytes = ("{'name':'lp','age':'23'}").getBytes();
        channel.basicPublish(AMQP_EXCHANGES, "critical.test", properties, messageBodyBytes);
    }
}
